$(function(){
    var request = moon.getRequest(location.search);
    var userId = request['id'];
    console.log(userId);
    $.getJsonData(contextPath+"/users/get/"+userId,{},{type:"Get"}).done(function(data){
        if(data.success){
            var result = data.result;
            console.log(result);
            $("#userName").val(result.userName);
            $("#nickname").val(result.nickname);
            $("#email").val(result.email);
            $("#phone").val(result.phone);
            $("#time").val(result.time);
            $("#description").val(result.description);
        }
    })
    $("#submit").click(function(){
        $("#right").validate("validate").done(function(result){
            var user={
                userName:$("#userName").val(),
                nickname:$("#nickname").val(),
                email:$("#email").val(),
                phone:$("#phone").val(),
                time:$("#time").val(),
                description:$("#description").val()
            }
            console.log(user);
            $.getJsonData(fullServerPath+"/users/complete",user,{type:"Put"}).done(function(data){
                console.log(data);
                if(data.success){
                    moon.info("修改成功","top");
                }else{
                    moon.error("修改失败","top");
                }
            }).fail(function(e){
                moon.error("服务器错误","top");
                console.log(e);
            });
        })
    })

    //loginOut
    $("#loginOut").on("click",function(){
        $.getJsonData(fullServerPath+"/users/logout",{},{type:"Post"}).done(function(data){
            if(data.success){
                moon.info("退出","top");
                window.location.href = contextPath+"login.html";
            }else{
                moon.error("退出失败","top");
            }
        })
    })

    $("#right").validate({align:'bottom',theme:"darkblue"});
})
